<template>
    <div class="newsinfo_container">
        <!-- 大标题 -->
        <h3 class="title">{{newsinfo.title}}</h3>
        <!-- 子标题 -->
        <p class="subtitle">
            <span>发表时间：{{newsinfo.add_time | dataFormat}}</span>
            <span>点击：{{newsinfo.click}}次</span>
        </p>
        <hr>
        <!-- 内容区域 -->
        <div class="content" v-html="newsinfo.content"></div>
        <!-- 评论子组件区域 -->
        <comment-box :id="this.id"></comment-box>
    </div>
</template>
<script>
    import { Toast } from 'mint-ui'
    import newsinfo from '../../../static/newsinfo.js'
    // 1. 导入 评论子组件
    import comment from '../subcomponents/comment.vue'
    export default {
        data(){
            return {
                id: this.$route.params.id,  // 将 URL 地址中传递过来的 Id值，挂载到 data 上，方便以后调用
                newsinfo: {} // 新闻对象
            }
        },
        created(){
           this.getNewsInfo(); 
        },
        methods: {
            getNewsInfo(){
                // 因数据不是自己的，接口调用不了，所以改用下面的下数据
                // this.$http.get('api/getnew/'+this.id).then(res=>{
                //     if(res.body.status==0){
                //         this.newsinfo=res.body.message[0]
                //     }else{
                //         Toast('获取新闻详情失败')
                //     }
                // });
                newsinfo.forEach(item=>{
                    if(item.id==this.id){
                        this.newsinfo=item;
                    }
                });
            }
        },
        components: {
            commentBox: comment
        }
    }
</script>
<style lang="scss">
    .newsinfo_container{
        padding: 0 10px;
        .title{
            font-size: 18px;
            margin: 10px 0;
            line-height: 22px;
            color: red;
        }
        .subtitle{
            font-size: 14px;
            color: #226aff;
            display: flex;
            justify-content: space-between;
        }
        .content{
            .detail_img{
                display: block;
                width: 100%;
                height: 230px;
                margin: 0 auto 6px;
            }
            .detail_text{
                display: block;
                color: #757575;
                font-size: 14px;
                line-height: 23px;
                margin-bottom: 6px;
            }
            .detail_text .blacktit{
                color: #333;
                font-size: 16px;
            }
            .nowsignup{
                width: 215px;
                line-height: 50px;
                background: #2b2b2b;
                color: #fff;
                font-size: 17px;
                margin-top: 15px;
            }
            .table {
                width: 100%;
                border: 1px solid #ccc;
                border-bottom: none;
                margin-bottom: 12px;
            }
            .tr {
                width: 100%;
                display: flex;
                justify-content: center;
                align-items: center;
                font-size: 14px;
                border-bottom: 1px solid #ccc;
            }
            .td {
                width: 20%;
                justify-content: center;
                display: flex;
                text-align: center;
                border-right: 2px solid #ddd;
                height: 100%;
            }
            .tr-h{
                line-height: 30px;
                border-bottom: none;
            }
            .td-1 {
                width: 20%;
                justify-content: center;
                display: flex;
                text-align: center;
                height: 100%;
            }
            .td-2 {
                width: 80%;
                height: 100%;
                max-width: 100%;
                justify-content: center;
                border-left: 1px solid #ccc;
                text-align: left;
                padding: 4px;
                box-sizing: border-box;
            }
            .bg-w{
                background: #afb4db;
                border-bottom: none;
            }
            .th {
                width: 20%;
                justify-content: center;
                color: #fff;
                display: flex;
                height: 28px;
                align-items: center;
            }
            .th-2 {
                width: 80%;
                justify-content: center;
                color: #fff;
                display: flex;
                height: 28px;
                align-items: center;
                max-height: 28px;
                max-width: 80%;
                border-left: 1px solid #ccc;
                box-sizing: border-box;
            }
            .th-text{
                width: 100%;
                color: #000;
                display: block;
                padding: 0 10px;
                box-sizing: border-box;
            }
            .black{
                font-size: 15px;
                font-weight: 600;
            }
        }
    }
</style>
